package com.yc.jiushujie.jsj_order.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yc.common.bean.Result;
import com.yc.jiushujie.entity.JsjCart;
import com.yc.jiushujie.jsj_order.mapper.JsjCartMapper;
import com.yc.jiushujie.jsj_order.mapper.JsjCategoryMapper;
import com.yc.jiushujie.jsj_order.service.IJsjCartService;
import com.yc.jiushujie.jsj_order.service.impl.JsjCartServiceImpl;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 无罪
 * @since 2022-08-03
 */
@RestController
@RequestMapping("/jiushujie/jsjCart")
public class JsjCartController {
    @Resource
    JsjCartMapper jsjCartMapper;
    @Resource
    JsjCartServiceImpl jsjCartService;
@GetMapping("add")
    public Result add(JsjCart jsjCart){
    LambdaQueryWrapper<JsjCart> lqw=new LambdaQueryWrapper<>();
    lqw.eq(JsjCart::getBid,jsjCart.getBid());
    lqw.eq(JsjCart::getUid,jsjCart.getUid());
    JsjCart dbcart=jsjCartMapper.selectOne(lqw);
    if (dbcart!=null){
        dbcart.setCount(dbcart.getCount()+ 1);
    }else {
        dbcart=jsjCart;
        dbcart.setCount(1);
    }
jsjCartService.saveOrUpdate(dbcart);
    return Result.success("添加购物车成功",null);
}
@RequestMapping("changeNum")
    public  Result changNum(JsjCart jsjCart){

    LambdaQueryWrapper<JsjCart> lqw=new LambdaQueryWrapper<>();
    lqw.eq(JsjCart::getBid,jsjCart.getBid());
    lqw.eq(JsjCart::getUid,jsjCart.getUid());
    JsjCart dbcart=jsjCartMapper.selectOne(lqw);
    System.out.println(dbcart);
dbcart.setCount(jsjCart.getCount());
    jsjCartService.saveOrUpdate(dbcart);
    return Result.success("修改商品数量成功",null);

}
}

